// pages/homes/homes.js
var requests = require("../../utils/requests.js")
var app = getApp();
var souceUrl = app.globalData.source;
var classifyList = "";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        img: "../../images/icon/1.png",
        /**datas: [
            { title: "有声小说", imageUrl: souceUrl + "ysxs.png", id: 1, sort: 1 },
            { title: "广场舞音乐", imageUrl: souceUrl + "gcwyl.png", id: 2, sort: 2 },
            { title: "情感故事", imageUrl: souceUrl + "qgdt.png", id: 3, sort: 3 },
            { title: "搞笑段子", imageUrl: souceUrl + "gxdz.png", id: 4, sort: 4 },
            { title: "故事会", imageUrl: souceUrl + "gsh.png", id: 5, sort: 5 },
            { title: "大家都在听", imageUrl: souceUrl + "djdzt.png", id: 6, sort: 6 },
            { title: "新鲜趣闻", imageUrl: souceUrl + "xxqw.png", id: 7, sort: 7 },
            { title: "家庭教育", imageUrl: souceUrl + "jtjy.png", id: 8, sort: 8 }
        ],**/

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        that.stratTime() //调用动画
        //var classifyList = ""//this.data.datas;
        //加载首页数据
		app.requestLoading(app.globalData.https + "programResource/category",
			"get", "", "加载中...", function (res) {
                if (res.code == 0) {console.log(res)
                    classifyList = res.data;
                    // 获取系统信息  
                    that.setData({
                        classifyList: classifyList,
                        souceUrl: souceUrl
                    });  
                }
            }, function (res) {
                console.log(res)
            }
        )

    },

    classifyBindtap: function (e) {
        var id = e.currentTarget.dataset.id;
        var classify = e.currentTarget.dataset.title;
        wx.navigateTo({
            url: "../home/classify/classify?id=" + id + "&classify=" + classify,
            success: function () {
                console.log('跳转到news页面成功')// success              
            },
            fail: function () {
                console.log('跳转到news页面失败')  // fail 
            }
        })
    },
    search: function () {
        wx.navigateTo({
            url: "../search/search",
            success: function () {
                console.log('跳转到news页面成功')// success              
            },
            fail: function () {
                console.log('跳转到news页面失败')  // fail 
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var that = this;
        requests.stop = false; //改变动画状态开始
        that.stratTime();//调用动画
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        requests.stop = true; //改变动画状态停止
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },

    /**
     *  动画切换
     */
    stratTime: function () {
        //每2秒，自动切换
        var that = this;
        var dt = 1;
        var img = "../../images/icon/1.png"
        var startTime = setInterval(function () {
            if (requests.stop) {
                clearInterval(startTime); //停止
            } else {
                if (dt === 1) {
                    dt = 2;
                    img = "../../images/icon/2.png"
                } else {
                    dt = 1;
                    img = "../../images/icon/1.png"
                }
                that.setData({
                    dt: dt,
                    img: img
                })
            }
        }, 2000);
    }
})